#include "spl.includes.h"
#include "splib.h"

using namespace SPLib;
using namespace SPLib::Windows;

Gdip::GdiplusStartupInput gGdiInput;
ULONG_PTR gGdiToken;

VOID SPLib::Windows::initWindows()
{
  WNDCLASSEX wClass;

  wClass.cbSize         = sizeof(wClass);
  wClass.style          = CS_GLOBALCLASS;
  wClass.lpfnWndProc    = WndBase::defWndProc;
  wClass.cbClsExtra     = 0;
  wClass.cbWndExtra     = 0;
  wClass.hInstance      = GetModuleHandle(NULL);
  wClass.hIcon          = NULL;
  wClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  wClass.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  wClass.lpszMenuName   = NULL;
  wClass.hIconSm        = NULL;
  wClass.lpszClassName  = SPL_WNDCLASS;

  RegisterClassEx(&wClass);

  wClass.style          = CS_GLOBALCLASS | CS_PARENTDC;
  wClass.lpszClassName  = SPL_CHILDCLASS;
  RegisterClassEx(&wClass);

  Gdip::GdiplusStartup(&gGdiToken, &gGdiInput, NULL);
}

VOID SPLib::Windows::uninitWindows()
{
  HINSTANCE wInstance = GetModuleHandle(NULL);

  Gdip::GdiplusShutdown(gGdiToken);

  UnregisterClass(SPL_WNDCLASS,   wInstance);
  UnregisterClass(SPL_CHILDCLASS, wInstance);
}
